package com.thingsgrid.device.controller;

import com.thingsgrid.device.entity.Topic;
import com.thingsgrid.device.service.ITopicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;

@RestController
//@AllArgsConstructor
@RequestMapping("/topic")
@Api(value = "", tags = "接口")
public class TopicController {
	@Autowired
	private ITopicService topicService;
	/**
	 * 新增
	 */
	@PostMapping("/submit")
	@ApiOperation(value = "新增", notes = "传入topic", position = 1)
	public void save(@Valid @RequestBody Topic topic) {
		topicService.saveTopic(topic);
	}

	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入ids", position = 2)
	public void remove(@ApiParam(value = "name", required = true) @RequestParam String ids) {
		topicService.removeTopic(ids);
	}

	/**
	 * 修改
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改", notes = "传入topic", position = 3)
	public void update(@Valid @RequestBody Topic topic) {
		topicService.updateTopic(topic);
	}
	/**
	 * 查找用户自定义topic
	 */
	@GetMapping("/selectUserTopic")
	@ApiOperation(value = "查询所有", notes = "", position = 4)
	public R<List<Topic>> selectUserTopic() {
		return R.data(topicService.findUserDefineTopic());
	}

	/**
	 * 查找所有
	 */
	@GetMapping("/selectAll")
	@ApiOperation(value = "查询所有", notes = "", position = 4)
	public R<List<Topic>> selectAll() {
		return R.data(topicService.findAll());
	}

	/**
	 * 根据functionName查信息
	 */
	@GetMapping("/detail")
	@ApiOperation(value = "查询一个", notes = "", position = 5)
	public Topic selectById(@ApiParam(value = "topicClassName", required = true) @RequestParam String topicClassName,String topicType) {
		return topicService.findTopicByName(topicClassName);
	}

	/**
	 * 分页查询
	 */
	@GetMapping("/list")
	@ApiOperation(value = "分页", notes = "传入页数和每页显示的条数", position = 6)
	public R<HashMap<String, Object>> pageList(@ApiParam(value = "页数和条数", required = true)
								   @RequestParam Integer current, Integer size, String productId) {
		return R.data(topicService.findAll(current, size, productId));

	}
}
